package com.ljx.itbbs.server.user.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ljx.itbbs.server.user.dao.RoleDao;
import com.ljx.itbbs.server.user.domain.entity.RoleEntity;
import com.ljx.itbbs.server.user.domain.vo.req.RoleGiveReq;
import com.ljx.itbbs.server.user.domain.vo.req.RoleSaveReq;
import com.ljx.itbbs.server.user.domain.vo.req.RoleUpdateReq;
import com.ljx.itbbs.server.user.domain.vo.resp.RoleResp;
import com.ljx.itbbs.server.user.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    @Override
    public List<RoleEntity> getByUId(Long userId) {
        return roleDao.getByUId(userId);
    }


    @Override
    public void saveRoleInfo(RoleSaveReq req) {
        RoleEntity roleEntity = BeanUtil.copyProperties(req, RoleEntity.class);
        roleDao.save(roleEntity);
    }

    @Override
    public void updateRoleInfo(RoleUpdateReq req) {
        roleDao.updateRoleInfo(req);
    }

    @Override
    public RoleResp getRoleInfo(Long roleId) {
        return BeanUtil.copyProperties(roleDao.getById(roleId), RoleResp.class);
    }

    @Override
    public List<RoleResp> getRoleList() {
        return BeanUtil.copyToList(roleDao.list(), RoleResp.class);
    }
}
